import 'package:flutter/material.dart';
import '../../components/form/LFormLogic.dart';
import '../../components/form/LFormPage.dart';
import '../../utils/SPutil.dart';
import '../../utils/Settings.dart';
import 'package:get/get.dart';
import 'package:flutter/services.dart';

import '../../utils/StoreData.dart';

class UserInfoPage extends StatefulWidget {
  const UserInfoPage({super.key});

  @override
  State<UserInfoPage> createState() => UserInfoState();
}

class UserInfoState extends State<UserInfoPage> with AutomaticKeepAliveClientMixin {

  late final LFormLogic lFormLogic;
  String formTag = "userInfoTag";
  List formItems = [
    {"field":'orgNo',"label":'单位',"component":'cascader',"readonly":true,"required":false,"isShowLabel":true,"dictCode":Settings.dictCodes["组织"]},
    {"field":'accountNo',"label":'账号',"component":'input',"readonly":true,"required":false,"isShowLabel":true,},
    {"field":'empNo',"label":'工号',"component":'input',"readonly":true,"required":false,"isShowLabel":true},
    {"field":'empName',"label":'姓名',"component":'input',"readonly":true,"required":false,"isShowLabel":true},
    // {"field":'profilePicture',"label":'头像',"component":'image',"readonly":true,"required":false,"isShowLabel":true},
  ];

  @override
  void initState() {
    lFormLogic = Get.put(LFormLogic(),tag:formTag);
    lFormLogic.init(formItems: formItems, formData: StoreData.sysEmp,tag: formTag,onChangeCallback: onChange);
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<LFormLogic>(tag: formTag);
    super.dispose();
  }

  ///内容改变后的回调
  void onChange(re){}

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        backgroundColor: Settings.backgroundColor,
        appBar: AppBar(
          title: const Text("个人信息"),
          centerTitle: true,
          elevation: 0,
        ),
        body:Column(
          children: [
            LFormPage(tag:formTag),
            SizedBox(
              height: 50,
              width: MediaQuery.of(context).size.width * 0.95,
              child: OutlinedButton.icon(
                icon: const Icon(Icons.output),
                label: const Text('退出登录',style: TextStyle(fontSize: 16,)),
                style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                    return Settings.primaryColor;
                  }),
                  foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                    return Colors.white;
                  }),
                ),
                onPressed:()async{
                  SPutil.clear();
                  // Get.offAllNamed("/userLogin");
                  await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
                },

              ),
            )

          ],
        )
    );
  }


}
